#ifndef H264ENCODER_H
#define H264ENCODER_H

#include"mediabase.h"
extern "C"{
#include<libavcodec/avcodec.h>
#include<libavutil/opt.h>
#include<libavutil/imgutils.h>
}
///
/// H264编码器
/// \brief The H264Encoder class
///
class H264Encoder
{
public:
    H264Encoder();
    virtual ~H264Encoder();
    ///
    /// \brief init
    /// \param properties
    ///     width:宽
    ///     height:高
    ///     fps:帧率
    ///     b_frames:b帧的连续数量
    ///     bit_rate:比特率
    ///     gop:连续多少帧后出现一个I帧
    ///     pix_fmt:像素格式
    ///
    virtual int init(const Properties& properties);
    ///
    /// 编码
    /// \brief encode
    /// \param yuv
    /// \param size
    /// \param pts
    /// \param pkt_frame
    /// \param ret
    /// \return
    ///
    virtual AVPacket* encode(uint8_t *yuv, int size, int64_t pts, int *pkt_frame, RET_CODE *ret);

    inline uint8_t *get_sps_data() {
           return (uint8_t *)_sps.c_str();
    }
    inline int get_sps_size(){
           return _sps.size();
    }
    inline uint8_t *get_pps_data() {
          return (uint8_t *)_pps.c_str();
    }
    inline int get_pps_size(){
          return _pps.size();
    }
    AVCodecContext *getCodecContext()
    {
        return _ctx;
    }

private:
    int _width = 0;
    int _height = 0;
    int _fps = 0; //帧率
    int _b_frames = 0;//连续B帧的数量
    int _bit_rate = 0;//码率
    int _gop = 0; //连续gop帧编码一个I帧，一般设置1s一个I帧，故gop一般是设置为帧率的相同值 todo: 设置0是不是代表每一帧都是I帧？
    bool _annexb = false;//开启最大编码效率
    int _threads = 1;
    int _pix_fmt = 0;

    std::string _sps;
    std::string _pps;
    std::string _codec_name;
    AVCodec *_codec = NULL;
    AVCodecContext *_ctx = NULL;
    AVDictionary* _dict = NULL;
    AVFrame *_frame = NULL;


};

#endif // H264ENCODER_H
